package weapp

import (
	"fmt"
	"github.com/medivhzhan/weapp"
	"go_api/pkg/setting"
)

func GetWeAppOpenId(code string) (bool, string) {
	fmt.Println("code=>",code)

	res, err :=  weapp.Login(setting.WeAppSetting.WeAppId, setting.WeAppSetting.WeAppSecret, code)
	if err != nil {
		fmt.Println("err=>",err)
		return false, "获取token 失败"
	}

	if res.SessionKey == "" {
		return false, "不存在的session_key"
	}

	return true, res.OpenID
}

//func SendTemplateMessage(openid,) {
//	msg := template.Message{
//		"keyword1": "content ...",
//		"keyword2": "content ...",
//	}
//
//	err := template.Send(openid, template, page, formID string, msg template.Message, emphasisKeyword, token string)
//}

//func GetAccessToken() {
//	tok, exp, err := token.AccessToken(setting.WeAppSetting.WeAppId, setting.WeAppSetting.WeAppSecret)
//	if err != nil {
//		logging.Warn(err)
//	}
//	keys := []string{
//		"weapp_token",
//	}
//}